<?php
namespace app\index\controller;
use app\index\controller\BaseController;
use Curl\Curl;
use think\Config;
use think\Request;

/**
 * 园区
 * Class Industry
 * @package app\index\controller
 */
class Park extends BaseController
{
    /**
     * 园区列表
     */
    public function parkList(){
        $reqData['industry_id'] = (int)$this->request->get('industry_id');
        $reqData['city_id'] = (int)$this->request->get('city_id');
        $reqData['chain_id'] = (int)$this->request->get('chain_id');
        $reqData['level'] = $this->request->get('level');
        $sortBy= $this->request->get('sortBy','zhpg');
        $city_name= $this->request->get('city_name','');
        $keywords = $this->request->get('keywords','');
        $method = $this->request->method();
        $page = $this->request->get('page',0);
        $limit = $this->request->get('limit',10);
        if ($reqData['city_id']==1){
            $reqData['city_id']=0;
        }
        // 业务
        $request_arr = ['sortBy'=> $sortBy,'level'=> $reqData['level'],'page'=>$page,'limit'=>$limit,'industry_id' => $reqData['industry_id'],'city_id' => $reqData['city_id'], 'keywords'=>$keywords,'chain_id'=>$reqData['chain_id']];
        $curl_data = $this->getBusiness('Common')->curl_request_data($method,$request_arr);
        if ($curl_data['status'] != 1){
            $this->result['status'] = $curl_data['status'];
            $this->result['msg'] = $curl_data['msg'];
            return json_encode($this->result);
        }

        $this->result['status'] = 1;
        $this->result['data'] = $curl_data['data']['data'];
        return json_encode($this->result);
    }

    /**
     * 园区详情
     * @return false|string
     */
    public function parkDetail()
    {
        $reqData['identification'] =$this->request->get('identification');
        $reqData['method'] = $this->request->method();
        $dispatch = $this->request->dispatch();
        // 业务
        $curl_data = $this->getBusiness('Common')->curl_request_data($reqData['method'] ,array('identification' => $reqData['identification']));
        if ($curl_data['status'] != 1){
            $this->result['status'] = $curl_data['status'];
            $this->result['msg'] = $curl_data['msg'];
            return json_encode($this->result);
        }

        //是否监控
        $flag = db('project')->where(['status' => 1, 'identification' => $reqData['identification']])->value('is_monitor');
        $curl_data['data']['data']['have']=empty($flag) ? 2 : $flag;

        // 我的收藏字段
        $single = array($curl_data['data']['data']);
        $return_data = $this->getBusiness('Common')->clickCollet($dispatch,$single,Config::get('collect.9'));
        $curl_data['data']['data'] = $return_data[0];

        $this->result['status'] = 1;
        $this->result['msg'] = 'success';
        $this->result['data'] = $curl_data['data']['data'];
        return json_encode($this->result);
    }
}